#include "tcpsever.h"
#include "./ui_tcpsever.h"

TCPSever::TCPSever(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::TCPSever)
{
    ui->setupUi(this);
    m_pTServer=new QTcpServer;
    m_pTSocket=new QTcpSocket;
    connect(ui->sendBtn,&QAbstractButton::clicked,this,&TCPSever::onSendMsgToClient);
    connect(ui->closeBtn,&QAbstractButton::clicked,this,&TCPSever::onCloseConnection);

}

TCPSever::~TCPSever()
{
    delete ui;
}

void TCPSever::onSendMsgToClient()
{
    m_pTSocket->write(ui->sendTextEdit->toPlainText().toUtf8().data());
    ui->sendTextEdit->clear();
}

void TCPSever::onCloseConnection()
{
    if(m_pTSocket->state()==QAbstractSocket::ConnectedState){
        m_pTSocket->disconnectFromHost();
        m_pTSocket->close();
    }
}

void TCPSever::onNewConnection()
{

}

void TCPSever::onReay()
{

}
